<?php
    $objSetor = new Setores();

    if (isset($_POST['acao']) && $_POST['acao'] == 'editar'){
        $setor = strip_tags($_POST['setor']);
        $ramal = strip_tags($_POST['ramal']);
        $cd = (int)$_POST['cd'];
                
        if ($setor == ''){
            echo '<script>alert("Preencha o Setor");location.href="?pagina=setor_adc";</script>';        
        }else{
            $dados = array($setor, $ramal, $cd);
                        
            if ($objSetor->editSetor($dados)){
                echo '<script>alert("Setor Atualizado com sucesso!");location.href="?pagina=setor";</script>';        
            }else{
                echo '<script>alert("Erro ao Atualizar!");location.href="?pagina=setor";</script>';        
            }
        }
    }
    
    
    if (isset($_GET['cd']) && $_GET['cd'] != ''){
        $cd = strip_tags($_GET['cd']);
    }else{
        echo '<script>location.href="?pagina=setor";</script>';
    }
    
    $dSetor = $objSetor->pegarSetorCd($cd);
    
?>

<div id="cadastro">
    <h1 class="titulo">Editar Setor</h1>
    <form action="" method="POST">
        <label class="l675">
            <span>Nome do Setor</span>
            <input type="text" name="setor" value="<?php echo $dSetor->SETOR; ?>"/>
        </label>
        <label class="l200">
            <span>Ramal</span>
            <input type="text" name="ramal" value="<?php echo $dSetor->RAMAL; ?>"/>
        </label>
        
        <input type="hidden" name="cd" value="<?php echo $dSetor->CD_SETOR; ?>"/>
        
        <input type="hidden" name="acao" value="editar"/>
        <input type="submit" value="Editar Setor" class="btn-salvar"/>
        <a href="?pagina=setor" class="btn-voltar">Voltar</a>
    </form>
</div>